<?php
namespace Common\Model;
use Think\Model;
use Think\Exception;
class AdminModel extends Model{
    private $_db="";
    public function __construct(){
        parent::__construct();
        $this->_db = M('admin');
    }
    public function getAdminByUsername($username){
        $res=$this->_db->where("username='".$username."'")->find();
        return $res;
    }
    public function getAdminByAdminId($adminId=0){
       $res=$this->_db->where('admin_id='.$adminId)->find(); 
       return $res;
    }
    //添加
    public function insert($data=array()){
     if(!$data||!is_array($data)){
         return 0;
      }   
      return $this->_db->add($data); 
    }
    public function updateAdminById($id,$data=array()){
        if(!$id ||!is_numeric($id)){
            throw_exception("Id不合法");
        }
        if(!$data||!is_array($data)){
            throw_exception("数据不合法");
        }
        return $this->_db->where('admin_id='.$id)->save($data);//更新数据 
    }
 
    //更新状态
    public function updateStatusById($id,$status){
        if(!$id || is_numeric($id)){
            throw_exception("ID不合法");
        }
       if(!is_numeric($status)){
           throw_exception("status不能为非数字");
        }
        $data['status']=$status;
        return $this->_db->where('admin_id='.$id)->save($data);
    }
   // 
    public function getAdmins(){
        
        
    }
    
    
}